package game.source.gui.price;

import game.source.gui.GuiComponent;
import game.source.price.GuiPriceInterface;

import java.awt.Point;
import java.awt.image.BufferedImage;

/**
 *GuiPrice:
 * Gerencia as informações gráficas dos prêmios
 */
public abstract class GuiPrice extends GuiComponent implements GuiPriceInterface{
	private CallBackPriceInterface	price;
	private Point					position;
	private double					vel;
	private double					accumulator;
	
	public GuiPrice(double vel){
		this.vel			= vel;
		this.accumulator	= 0;
	}
	
	@Override
	public void setPrice(CallBackPriceInterface price) {
		this.price = price; 
	}

	@Override
	public void setStartPosition(Point position) {
		this.position = new Point(position);
	}
	
	public abstract BufferedImage getImage();
	
	@Override
	public int getX0(){//Retorna a posição x superior esquerda.
		return this.position.x;
	}

	@Override
	public int getY0(){//Retorna a posição y superior esquerda.
		return this.position.y;
	}

	@Override
	public int getWidth(){//Retorna a largura da imagem
		return this.getImage().getWidth();
	}

	@Override
	public int getHeight(){//Retorna a altura da imagem
		return this.getImage().getHeight();
	}

	@Override
	public byte	getPixelAlpha(int x,int y){//Retorna o canal alpha do pixel de coordenadas passadas no argumento
		int pixel = this.getImage().getRGB(x,y);
		byte alpha = (byte)((pixel >> 24) & 0xFF);
		return alpha;
	}

	@Override
	public void show(long time) {
		this.accumulator += this.vel*time/1000;
		if(this.accumulator >= 1){
			this.position.y += (int)this.accumulator;
			this.accumulator -= (int)this.accumulator;
		}
		this.getGraphics().drawImage(this.getImage(), this.position.x, this.position.y,null);	
	}
	
	public void action(){//Acão que o prêmio realiza
		this.price.action();
	}

}
